

function init() {
    jsonOb = CasinoGame;
    window.onresize = funcRef;
    var ok = document.getElementById("ok");
    var floater = document.getElementById("floater");


    funcRef();
    function funcRef() {
        // toggleFullScreen();
        var width = document.body.clientWidth;
        var height = document.body.clientHeight;
        // var height = window.screen.height;
        ok.style.height = parseInt(width) * 9 / 16 + "px";

        if (deviceType() != "pc" && checkSceenState() == "hen") {
            floater.style.display = "none";

        } else {
            floater.style.display = "block";
        }

        if ((width / height) > 1.77) {
            ok.style.height = height + "px";
            ok.style.width = height * 16 / 9 + "px";
        } else {
            ok.style.height = parseInt(width) * 9 / 16 + "px";
            ok.style.width = width + "px";
        }

        floater.style["margin-bottom"] = (-1) * parseInt(ok.style.height) / 2 + "px";

    }

    var goFS = document;
    goFS.addEventListener("click", function () {
        if (deviceType() == "pc") {
            return;
        }
        toggleFullScreen();
    }, false);

    function toggleFullScreen() {
        var doc = window.document;
        var docEl = doc.documentElement;

        var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
        var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;

        if (!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
            requestFullScreen.call(docEl);
        }
        else {
            cancelFullScreen.call(doc);
        }
    }



    function checkSceenState() {
        if (window.orientation === 180 || window.orientation === 0) {
//          console.log("shu");
            return "shu";
        }
        if (window.orientation === 90 || window.orientation === -90) {
//          console.log("hen");
            return "hen";
        }
    }
    //判断手机横竖屏状态：
    window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function () {
        funcRef();
    }, false);

    Socket = (function () {
        var callFn = new Function('');

        var SERVER_PORT = 8082;
//      console.log(jsonOb.UrlBase);
        var URL_SERVER = jsonOb.UrlBase;
        var socket = io.connect(URL_SERVER);
        socket.on('connect', function () {
            socket.on('ResponseResult', function (ret) {
                //                    console.log(ret);
                var ob = JSON.parse(ret);
                if(Container){
                    Container.SetData(ob.Action,ob.ScreenData);
                }
                if (ob.Action == "TouchToken") {
                    return;
                }
                callFn(ob);

            });
            socket.on("disconnect", function () {
//              console.log("短线");
                // socket.disconnect();
                reconFn();
            });
            socket.on("error", function () {
//              console.log("短线");
                // socket.disconnect();
                reconFn();
            });

            var vtoken_interval = CasinoGame.vtoken_interval || 20;
            setInterval(function () {
                serverDispatch('TouchToken', [], function (data) {
//                  console.log("TouchToken", data);
                });
            }, 1000 * vtoken_interval);



        });
        return {
            sendData: function (json) {
                //console.log("发送信号",json);
                try {
                    socket.emit('Action', json);
                } catch (e) {

                }
                return this;
            },
            then: function (fn) {
                callFn = fn;
                return this;
            }
        }

    } ());
}

function deviceType() {
    var index = "pc"
    var ua = navigator.userAgent;
    var agent = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
    for (var i = 0; i < agent.length; i++) {
        if (ua.indexOf(agent[i]) > 0) {
            index = agent[i];
            break;
        }
    }
    return index;
}


function setScreenAction(data){
    Container.SetData(data);
}